package cn.edu.gsau.info.service.impl;


import cn.edu.gsau.info.dao.UserRoleDao;

import cn.edu.gsau.info.models.BigUser;
import cn.edu.gsau.info.models.ResponseResult;
import cn.edu.gsau.info.models.Userrole;

import cn.edu.gsau.info.service.IUserRoleService;
import cn.edu.gsau.info.service.IUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@JsonSerialize
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleDao,Userrole> implements IUserRoleService {
@Autowired
UserRoleDao userRoleDao;
@Transactional
    public ResponseResult insert(BigUser bigUser) {
        System.out.println(bigUser.getUserrole());

        for (int i=0;i<bigUser.getUserrole().size()-1;i++){

            Userrole userrole=new Userrole();
            userrole.setUserId(bigUser.getUser().getId());
            userrole.setRoleId(bigUser.getUserrole().get(i).getRoleId());
            userRoleDao.insert(userrole);
        }


         return new ResponseResult(200,"成功");

    }


}
